package com.example.jiaopin.Controller;

import com.example.jiaopin.model.CourseEvaluation;
import com.example.jiaopin.Service.CourseEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course-evaluations")
public class CourseEvaluationController {

    @Autowired
    private CourseEvaluationService courseEvaluationService;

    // 增加课程评价
    @PostMapping("/add")
    public String addCourseEvaluation(@RequestBody CourseEvaluation courseEvaluation) {
        int result = courseEvaluationService.addCourseEvaluation(courseEvaluation);
        if (result > 0) {
            return "课程评价添加成功";
        } else {
            return "课程评价添加失败";
        }
    }

    // 删除课程评价
    @DeleteMapping("/delete/{evaluationId}")
    public String deleteCourseEvaluation(@PathVariable Integer evaluationId) {
        int result = courseEvaluationService.deleteCourseEvaluation(evaluationId);
        if (result > 0) {
            return "课程评价删除成功";
        } else {
            return "课程评价删除失败";
        }
    }

    // 根据课程ID获取所有评价
    @GetMapping("/course/{courseId}")
    public List<CourseEvaluation> getEvaluationsByCourseId(@PathVariable Integer courseId) {
        return courseEvaluationService.getEvaluationsByCourseId(courseId);
    }
}
